var rootURL=getRootPath();
var totalRecord,currentPage;
 //ajax请求，要到分页数据
$(function(){
    //去首页
    to_page(1);
    $("#room_Add_Modal_btn").click(function () {
        reset_form("#roomAddModal form");
        $("#roomAddModal").modal({
            backdrop: "static"
        });
    });

    $("#room_Update_Modal_btn").on(function () {
        $("#roomUpdateModal").modal({
            backdrop: "static"
        });
    });

    selGrade(1);
    selClasss('1',1);
    selGrade(2);
    selClasss('2',2);
    $("#grade1").change(function () {
        course.grade=null;
        var options=$("#grade1 option:selected");
        var grade=options.val();
        course.grade=grade;
        selClasss(grade,1);
    });
    $("#classs1").change(function () {
        course.classs=null;
        var options=$("#classs1 option:selected");
        var classs=options.val();
        course.classs=classs;
    });
    $("#grade2").change(function () {
        course.grade=null;
        var options=$("#grade2 option:selected");
        var grade=options.val();
        course.grade=grade;
        selClasss(grade,2);
    });
    $("#classs2").change(function () {
        course.classs=null;
        var options=$("#classs2 option:selected");
        var classs=options.val();
        course.classs=classs;
    });
});
function to_page(pn) {
    $.ajax({
        url:rootURL+"selAllRoom",
        data:"pn="+pn,
        type:"GET",
        success:function(result){
            //console.log(result);
            //显示数据
            build_room_table(result);
            //显示分页信息
            build_page_info(result);
            //显示分页条
            build_page_nav(result);
        }
    });
}
function build_room_table(result) {
    $("#room_table tbody").empty();
    var room=result.extend.pageInfo.list;
    $.each(room,function (index,item) {
        var idTd=$("<td></td>").append(item.id);
        var nameTd=$("<td></td>").append(item.name);
        var equipmentIdTd=$("<td></td>").append(item.equipmentId);
        var roomUseTd=$("<td></td>").append(item.roomUse=='1'?"使用中":"未使用");
        var roomDetailsTd=$("<td></td>").append(item.standby2+" - "+item.standby3);
        var inputTimeTd=$("<td></td>").append(formatDate(item.inputTime));
        var roomTypeTd=$("<td></td>").append(item.roomType=='1'?"会议室":"教室");

        var updBtn = $("<button></button>").addClass("btn btn-primary btn-sm upd_btn")
            .append($("<span></span>").addClass("glyphicon glyphicon-pencil")).append("编辑");
        updBtn.attr("upd-id",item.id);
        var delBtn =  $("<button></button>").addClass("btn btn-danger btn-sm del_btn")
            .append($("<span></span>").addClass("glyphicon glyphicon-trash")).append("删除");
        delBtn.attr("del-id",item.id);
        var btnTd = $("<td></td>").append(updBtn).append(" ").append(delBtn);

        $("<tr></tr>")
            .append(idTd)
            .append(nameTd)
            .append(equipmentIdTd)
            .append(roomUseTd)
            .append(roomDetailsTd)
            .append(inputTimeTd)
            .append(roomTypeTd)
            .append(btnTd)
            .appendTo("#room_table tbody");
    });
}
function build_page_info(result){
    $("#page_info_area").empty();
    $("#page_info_area").append("当前"+result.extend.pageInfo.pageNum+"页,总"+
        result.extend.pageInfo.pages+"页,总"+
        result.extend.pageInfo.total+"条记录");
    totalRecord = result.extend.pageInfo.total;
    currentPage = result.extend.pageInfo.pageNum;
}
//解析显示分页条，点击分页要能去下一页....
function build_page_nav(result){
    //page_nav_area
    $("#page_nav_area").empty();
    var ul = $("<ul></ul>").addClass("pagination");

    //构建元素
    var firstPageLi = $("<li></li>").append($("<a></a>").append("首页").attr("href","#"));
    var prePageLi = $("<li></li>").append($("<a></a>").append("&laquo;"));
    if(result.extend.pageInfo.hasPreviousPage == false){
        firstPageLi.addClass("disabled");
        prePageLi.addClass("disabled");
    }else{
        //为元素添加点击翻页的事件
        firstPageLi.click(function(){
            to_page(1);
        });
        prePageLi.click(function(){
            to_page(result.extend.pageInfo.pageNum -1);
        });
    }

    var nextPageLi = $("<li></li>").append($("<a></a>").append("&raquo;"));
    var lastPageLi = $("<li></li>").append($("<a></a>").append("末页").attr("href","#"));
    if(result.extend.pageInfo.hasNextPage == false){
        nextPageLi.addClass("disabled");
        lastPageLi.addClass("disabled");
    }else{
        nextPageLi.click(function(){
            to_page(result.extend.pageInfo.pageNum +1);
        });
        lastPageLi.click(function(){
            to_page(result.extend.pageInfo.pages);
        });
    }

    //添加首页和前一页 的提示
    ul.append(firstPageLi).append(prePageLi);
    //1,2，3遍历给ul中添加页码提示
    $.each(result.extend.pageInfo.navigatepageNums,function(index,item){

        var numLi = $("<li></li>").append($("<a></a>").append(item));
        if(result.extend.pageInfo.pageNum == item){
            numLi.addClass("active");
        }
        numLi.click(function(){
            to_page(item);
        });
        ul.append(numLi);
    });
    //添加下一页和末页 的提示
    ul.append(nextPageLi).append(lastPageLi);

    //把ul加入到nav
    var navEle = $("<nav></nav>").append(ul);
    navEle.appendTo("#page_nav_area");
}

//清空表单样式及内容
function reset_form(ele){
    $(ele)[0].reset();
    //清空表单样式
    $(ele).find("*").removeClass("has-error has-success");
    $(ele).find(".help-block").text("");
}


$(function () {
    $("#room_save_btn").click(function () {

        var addId=$("#id_add_input").val();
        var addname=$("#name_add_input").val();
        var addequipmentId=$("#equipmentId_add_input").val();
        var addroomUse=$("#roomAddModal input[name=roomUse]:checked").val();
        var addroomDetails=$("#roomDetails_add_input").val();
        var addroomType=$("#roomAddModal input[name=roomType]:checked").val();
        var addstandby1=$("#standby1_add_input").val();
        $.ajax({
            url:rootURL+"/addRoom",
            type:"GET",
            data:{
                id:addId,
                name:addname,
                equipmentId:addequipmentId,
                roomUse:addroomUse,
                roomDetails:addroomDetails,
                roomType:addroomType,
                standby1:addstandby1,
                standby2:$("#grade1 option:selected").val(),
                standby3:$("#classs1 option:selected").val()
            },
            success:function (result) {
                $("#roomAddModal").modal('hide');
                to_page(totalRecord);
                reset_form("#roomAddModal form");
            }
        });
    });
});

    $(function () {
        $(document).on("click", ".upd_btn", function () {
            getRoom($(this).attr("upd-id"));
            $("#room_Update_Modal_btn").attr("upd-id", $(this).attr("upd-id"));
            $("#roomUpdateModal").modal({
                backdrop: "static"
            });
        });

        function getRoom(id) {
            $.ajax({
                url: rootURL+"selRoom",
                type: "GET",
                data: "id="+id,
                success: function (result) {
                    console.log(result);
                    var roomData = result.extend.room;
                    $("#id_update_input").val(roomData.id);
                    $("#name_update_input").val(roomData.name);
                    $("#equipmentId_update_input").val(roomData.equipmentId);
                    $("#roomUpdateModal input:radio[name='roomUse'][value="+roomData.roomUse+"]").prop('checked','true');
                    $("#roomDetails_update_input").val(roomData.roomDetails);
                    $("#inputTime_update_input").val(formatDate(roomData.inputTime));
                    $("#roomUpdateModal input:radio[name='roomType'][value="+roomData.roomType+"]").prop('checked','true');
                    $("#standby1_update_input").val(roomData.standby1);

                }
            });
        }
        //点击更新
        $("#room_update_btn").click(function(){

            var updateId=$("#id_update_input").val();
            var updateName=$("#name_update_input").val();
            var updateequipmentId=$("#equipmentId_update_input").val();
            var updateroomUse=$("#roomUpdateModal input[name=roomUse]").val();
            var updateroomDetails=$("#roomDetails_update_input").val();
            var updateinputTime=formatDate($("#inputTime_update_input").val());
            var updateroomType=$("#roomUpdateModal input[name=roomType]").val();
            var updatestandby1=$("#standby1_update_input").val();

            //2、发送ajax请求保存
            $.ajax({
                url:rootURL+"/updRoom",
                type:"GET",
                data:
                    {   id:updateId,
                        name:updateName,
                        equipmentId:updateequipmentId,
                        roomUse:updateroomUse,
                        roomDetails:updateroomDetails,
                        inputTime:updateinputTime,
                        roomType:updateroomType,
                        standby1:updatestandby1,
                        standby2:$("#grade2 option:selected").val(),
                        standby3:$("#classs2 option:selected").val()
                    },
                success:function(result){
                    //(result.msg);
                    //1、关闭对话框
                    $("#roomUpdateModal").modal("hide");
                    //2、回到本页面
                    to_page(currentPage);
                }
            });
        });


    })
// $(function () {
//     $(document).on("click",".del_btn",function(){
//
//         delRoom($(this).attr("del-id"));
//     })
//     function delRoom(id) {
//
//         $.ajax({
//             url:rootURL+"delRoom",
//             type:"GET",
//             data:"id="+id,
//             success: function (result) {
//                 alert(result.msg);
//                 to_page(currentPage);
//             }
//         });
//     }
// })

$(function () {

    $(document).on("click",".del_btn",function(){
        var name = $(this).parents("tr").find("td:eq(1)").text();
        // alert(releasePeople);
        var id=$(this).attr("del-id");
        // alert(id);
        if(confirm("确认删除【"+name+"】吗？")) {
            $.ajax({
                url:rootURL+"delRoom",
             type:"GET",
            data:"id="+id,
                success: function (result) {
                    //alert(result.msg);
                    to_page(currentPage);
                }
            });
        }
    })
})

          //根据名字查找
function find_name() {
    var name = document.getElementById("name").value;
   // alert(name);
    if (name == null || name == "") {
        to_page(1);
    } else {
        to_name_page(1);
        $("#name").val("");
    }
    function to_name_page(pn) {
        $.ajax({
            url: rootURL + "/selRoomByName",
            data:
                {
                    pn: pn,
                    name: name
                },
            //"releaseState="+stateId,
            type: "GET",
            success: function (result) {
               console.log(result);
                build_name_table(result);
                //2、解析并显示分页信息
                build_name_info(result);
                //3、解析显示分页条数据
                build_name_nav(result);
            }
        });
    }
    function build_name_table(result) {
        $("#room_table tbody").empty();
        var room=result.extend.pageInfo.list;
        $.each(room,function (index,item) {
            var idTd=$("<td></td>").append(item.id);
            var nameTd=$("<td></td>").append(item.name);
            var equipmentIdTd=$("<td></td>").append(item.equipmentId);
            var roomUseTd=$("<td></td>").append(item.roomUse=='1'?"使用中":"未使用");
            var roomDetailsTd=$("<td></td>").append(item.roomDetails);
            var inputTimeTd=$("<td></td>").append(formatDate(item.inputTime));
            var roomTypeTd=$("<td></td>").append(item.roomType=='1'?"会议室":"教室");

            var updBtnName = $("<button></button>").addClass("btn btn-primary btn-sm upd_btn_name")
                .append($("<span></span>").addClass("glyphicon glyphicon-pencil")).append("编辑");
            updBtnName.attr("upd-id-name",item.id);
            var delBtnName =  $("<button></button>").addClass("btn btn-danger btn-sm del_btn_name")
                .append($("<span></span>").addClass("glyphicon glyphicon-trash")).append("删除");
            delBtnName.attr("del-id-name",item.id);
            var btnTd = $("<td></td>").append(updBtnName).append(" ").append(delBtnName);

            $("<tr></tr>")
                .append(idTd)
                .append(nameTd)
                .append(equipmentIdTd)
                .append(roomUseTd)
                .append(roomDetailsTd)
                .append(inputTimeTd)
                .append(roomTypeTd)
                .append(btnTd)
                .appendTo("#room_table tbody");
        });
    }
    function build_name_info(result){
        $("#page_info_area").empty();
        $("#page_info_area").append("当前"+result.extend.pageInfo.pageNum+"页,总"+
            result.extend.pageInfo.pages+"页,总"+
            result.extend.pageInfo.total+"条记录");
        totalRecord = result.extend.pageInfo.total;
        currentPage = result.extend.pageInfo.pageNum;
    }
//解析显示分页条，点击分页要能去下一页....
    function build_name_nav(result){
        //page_nav_area
        $("#page_nav_area").empty();
        var ul = $("<ul></ul>").addClass("pagination");

        //构建元素
        var firstPageLi = $("<li></li>").append($("<a></a>").append("首页").attr("href","#"));
        var prePageLi = $("<li></li>").append($("<a></a>").append("&laquo;"));
        if(result.extend.pageInfo.hasPreviousPage == false){
            firstPageLi.addClass("disabled");
            prePageLi.addClass("disabled");
        }else{
            //为元素添加点击翻页的事件
            firstPageLi.click(function(){
                to_name_page(1);
            });
            prePageLi.click(function(){
                to_name_page(result.extend.pageInfo.pageNum -1);
            });
        }

        var nextPageLi = $("<li></li>").append($("<a></a>").append("&raquo;"));
        var lastPageLi = $("<li></li>").append($("<a></a>").append("末页").attr("href","#"));
        if(result.extend.pageInfo.hasNextPage == false){
            nextPageLi.addClass("disabled");
            lastPageLi.addClass("disabled");
        }else{
            nextPageLi.click(function(){
                to_name_page(result.extend.pageInfo.pageNum +1);
            });
            lastPageLi.click(function(){
                to_name_page(result.extend.pageInfo.pages);
            });
        }

        //添加首页和前一页 的提示
        ul.append(firstPageLi).append(prePageLi);
        //1,2，3遍历给ul中添加页码提示
        $.each(result.extend.pageInfo.navigatepageNums,function(index,item){

            var numLi = $("<li></li>").append($("<a></a>").append(item));
            if(result.extend.pageInfo.pageNum == item){
                numLi.addClass("active");
            }
            numLi.click(function(){
                to_name_page(item);
            });
            ul.append(numLi);
        });
        //添加下一页和末页 的提示
        ul.append(nextPageLi).append(lastPageLi);

        //把ul加入到nav
        var navEle = $("<nav></nav>").append(ul);
        navEle.appendTo("#page_nav_area");
    }

    $(function () {
        $(document).on("click", ".upd_btn_name", function () {
           // alert("upd");
            getRoom($(this).attr("upd-id-name"));
            $("#room_Update_Modal_btn").attr("upd-id-name", $(this).attr("upd-id-name"));
            $("#roomUpdateModal").modal({
                backdrop: "static"
            });
        });

        function getRoom(id) {
           // alert(id);
            $.ajax({
                url: rootURL+"selRoom",
                type: "GET",
                data: "id="+id,
                success: function (result) {
                    console.log(result);
                    var roomData = result.extend.room;
                    $("#id_update_input").val(roomData.id);
                    $("#name_update_input").val(roomData.name);
                    $("#equipmentId_update_input").val(roomData.equipmentId);
                    $("#roomUpdateModal input:radio[name='roomUse'][value="+roomData.roomUse+"]").prop('checked','true');
                    $("#roomDetails_update_input").val(roomData.roomDetails);
                    $("#inputTime_update_input").val(formatDate(roomData.inputTime));
                    $("#roomUpdateModal input:radio[name='roomType'][value="+roomData.roomType+"]").prop('checked','true');
                    $("#standby1_update_input").val(roomData.standby1);

                }
            });
        }
        //点击更新
        $("#room_update_btn").click(function(){

            var updateId=$("#id_update_input").val();
            var updateName=$("#name_update_input").val();
            var updateequipmentId=$("#equipmentId_update_input").val();
            var updateroomUse=$("#roomUpdateModal input[name=roomUse]").val();
            var updateroomDetails=$("#roomDetails_update_input").val();
            var updateinputTime=formatDate($("#inputTime_update_input").val());
            var updateroomType=$("#roomUpdateModal input[name=roomType]").val();
            var updatestandby1=$("#standby1_update_input").val();

            //2、发送ajax请求保存
            $.ajax({
                url:rootURL+"/updRoom",
                type:"GET",
                data:
                    {   id:updateId,
                        name:updateName,
                        equipmentId:updateequipmentId,
                        roomUse:updateroomUse,
                        roomDetails:updateroomDetails,
                        inputTime:updateinputTime,
                        roomType:updateroomType,
                        standby1:updatestandby1
                    },
                success:function(result){
                   // alert(result.msg);
                    //1、关闭对话框
                    $("#roomUpdateModal").modal("hide");
                    //2、回到本页面
                    to_name_page(currentPage);
                }
            });
        });


    })
    // $(function () {
    //     $(document).on("click",".del_btn_name",function(){
    //
    //         delRoom($(this).attr("del-id-name"));
    //     })
    //     function delRoom(id) {
    //
    //         $.ajax({
    //             url:rootURL+"delRoom",
    //             type:"GET",
    //             data:"id="+id,
    //             success: function (result) {
    //                 alert(result.msg);
    //                 to_name_page(currentPage);
    //             }
    //         });
    //     }
    // })

    $(function () {

        $(document).on("click",".del_btn_name",function(){
            var name = $(this).parents("tr").find("td:eq(1)").text();
            // alert(releasePeople);
            var id=$(this).attr("del-id-name");
            // alert(id);
            if(confirm("确认删除【"+name+"】吗？")) {
                $.ajax({
                    url:rootURL+"delRoom",
                    type:"GET",
                    data:"id="+id,
                    success: function (result) {
                        //alert(result.msg);
                        to_name_page(currentPage);
                    }
                });
            }
        })
    })




}

//................................................................................................................
//根据设备ID查找
function equipmentid() {
    var equipment = document.getElementById("equipment").value;
   // alert(equipment);
    if (equipment == null || equipment == "") {
        to_page(1);

    } else {
        to_equipment_page(1);
        $("#equipment").val("");
    }

    function  to_equipment_page(pn) {
        $.ajax({
            url: rootURL + "/selRoomByEid",
            data:
                {
                    pn: pn,
                    equipmentId: equipment
                },
            //"releaseState="+stateId,
            type: "GET",
            success: function (result) {
                //  console.log(result);
                build_equipment_table(result);
                //2、解析并显示分页信息
                build_equipment_info(result);
                //3、解析显示分页条数据
                build_equipment_nav(result);
            }
        });
    }
    function build_equipment_table(result) {
        $("#room_table tbody").empty();
        var room=result.extend.pageInfo.list;
        $.each(room,function (index,item) {
            var idTd=$("<td></td>").append(item.id);
            var nameTd=$("<td></td>").append(item.name);
            var equipmentIdTd=$("<td></td>").append(item.equipmentId);
            var roomUseTd=$("<td></td>").append(item.roomUse=='1'?"使用中":"未使用");
            var roomDetailsTd=$("<td></td>").append(item.roomDetails);
            var inputTimeTd=$("<td></td>").append(formatDate(item.inputTime));
            var roomTypeTd=$("<td></td>").append(item.roomType=='1'?"会议室":"教室");

            var updBtnEquipment = $("<button></button>").addClass("btn btn-primary btn-sm upd_btn_equipment")
                .append($("<span></span>").addClass("glyphicon glyphicon-pencil")).append("编辑");
            updBtnEquipment.attr("upd-id-equipment",item.id);
            var delBtnEquipment =  $("<button></button>").addClass("btn btn-danger btn-sm del_btn_equipment")
                .append($("<span></span>").addClass("glyphicon glyphicon-trash")).append("删除");
            delBtnEquipment.attr("del-id-equipment",item.id);
            var btnTd = $("<td></td>").append(updBtnEquipment).append(" ").append(delBtnEquipment);

            $("<tr></tr>")
                .append(idTd)
                .append(nameTd)
                .append(equipmentIdTd)
                .append(roomUseTd)
                .append(roomDetailsTd)
                .append(inputTimeTd)
                .append(roomTypeTd)
                .append(btnTd)
                .appendTo("#room_table tbody");
        });
    }
    function build_equipment_info(result){
        $("#page_info_area").empty();
        $("#page_info_area").append("当前"+result.extend.pageInfo.pageNum+"页,总"+
            result.extend.pageInfo.pages+"页,总"+
            result.extend.pageInfo.total+"条记录");
        totalRecord = result.extend.pageInfo.total;
        currentPage = result.extend.pageInfo.pageNum;
    }
//解析显示分页条，点击分页要能去下一页....
    function build_equipment_nav(result){
        //page_nav_area
        $("#page_nav_area").empty();
        var ul = $("<ul></ul>").addClass("pagination");

        //构建元素
        var firstPageLi = $("<li></li>").append($("<a></a>").append("首页").attr("href","#"));
        var prePageLi = $("<li></li>").append($("<a></a>").append("&laquo;"));
        if(result.extend.pageInfo.hasPreviousPage == false){
            firstPageLi.addClass("disabled");
            prePageLi.addClass("disabled");
        }else{
            //为元素添加点击翻页的事件
            firstPageLi.click(function(){
                to_equipment_page(1);
            });
            prePageLi.click(function(){
                to_equipment_page(result.extend.pageInfo.pageNum -1);
            });
        }

        var nextPageLi = $("<li></li>").append($("<a></a>").append("&raquo;"));
        var lastPageLi = $("<li></li>").append($("<a></a>").append("末页").attr("href","#"));
        if(result.extend.pageInfo.hasNextPage == false){
            nextPageLi.addClass("disabled");
            lastPageLi.addClass("disabled");
        }else{
            nextPageLi.click(function(){
                to_equipment_page(result.extend.pageInfo.pageNum +1);
            });
            lastPageLi.click(function(){
                to_equipment_page(result.extend.pageInfo.pages);
            });
        }

        //添加首页和前一页 的提示
        ul.append(firstPageLi).append(prePageLi);
        //1,2，3遍历给ul中添加页码提示
        $.each(result.extend.pageInfo.navigatepageNums,function(index,item){

            var numLi = $("<li></li>").append($("<a></a>").append(item));
            if(result.extend.pageInfo.pageNum == item){
                numLi.addClass("active");
            }
            numLi.click(function(){
                to_equipment_page(item);
            });
            ul.append(numLi);
        });
        //添加下一页和末页 的提示
        ul.append(nextPageLi).append(lastPageLi);

        //把ul加入到nav
        var navEle = $("<nav></nav>").append(ul);
        navEle.appendTo("#page_nav_area");
    }

    $(function () {
        $(document).on("click", ".upd_btn_equipment", function () {
           // alert("upd");
            getRoom($(this).attr("upd-id-equipment"));
            $("#room_Update_Modal_btn").attr("upd-id-equipment", $(this).attr("upd-id-equipment"));
            $("#roomUpdateModal").modal({
                backdrop: "static"
            });
        });

        function getRoom(id) {
          //  alert(id);
            $.ajax({
                url: rootURL+"selRoom",
                type: "GET",
                data: "id="+id,
                success: function (result) {
                    console.log(result);
                    var roomData = result.extend.room;
                    $("#id_update_input").val(roomData.id);
                    $("#name_update_input").val(roomData.name);
                    $("#equipmentId_update_input").val(roomData.equipmentId);
                    $("#roomUpdateModal input:radio[name='roomUse'][value="+roomData.roomUse+"]").prop('checked','true');
                    $("#roomDetails_update_input").val(roomData.roomDetails);
                    $("#inputTime_update_input").val(formatDate(roomData.inputTime));
                    $("#roomUpdateModal input:radio[name='roomType'][value="+roomData.roomType+"]").prop('checked','true');
                    $("#standby1_update_input").val(roomData.standby1);

                }
            });
        }
        //点击更新
        $("#room_update_btn").click(function(){

            var updateId=$("#id_update_input").val();
            var updateName=$("#name_update_input").val();
            var updateequipmentId=$("#equipmentId_update_input").val();
            var updateroomUse=$("#roomUpdateModal input[name=roomUse]").val();
            var updateroomDetails=$("#roomDetails_update_input").val();
            var updateinputTime=formatDate($("#inputTime_update_input").val());
            var updateroomType=$("#roomUpdateModal input[name=roomType]").val();
            var updatestandby1=$("#standby1_update_input").val();

            //2、发送ajax请求保存
            $.ajax({
                url:rootURL+"/updRoom",
                type:"GET",
                data:
                    {   id:updateId,
                        name:updateName,
                        equipmentId:updateequipmentId,
                        roomUse:updateroomUse,
                        roomDetails:updateroomDetails,
                        inputTime:updateinputTime,
                        roomType:updateroomType,
                        standby1:updatestandby1
                    },
                success:function(result){
                   // alert(result.msg);
                    //1、关闭对话框
                    $("#roomUpdateModal").modal("hide");
                    //2、回到本页面
                    to_equipment_page(currentPage);
                }
            });
        });


    })
//     $(function () {
//         $(document).on("click",".del_btn_equipment",function(){
//
//             delRoom($(this).attr("del-id-equipment"));
//         })
//         function delRoom(id) {
//
//             $.ajax({
//                 url:rootURL+"delRoom",
//                 type:"GET",
//                 data:"id="+id,
//                 success: function (result) {
//                     alert(result.msg);
//                     to_equipment_page(currentPage);
//                 }
//             });
//         }
//     })
//
// }

    $(function () {

        $(document).on("click",".del_btn_equipment",function(){
            var name = $(this).parents("tr").find("td:eq(1)").text();
            // alert(releasePeople);
            var id=$(this).attr("del-id-equipment");
            // alert(id);
            if(confirm("确认删除【"+name+"】吗？")) {
                $.ajax({
                    url:rootURL+"delRoom",
                    type:"GET",
                    data:"id="+id,
                    success: function (result) {
                        //alert(result.msg);
                        to_equipment_page(currentPage);
                    }
                });
            }
        })
    })
}

//查询年级
function selGrade(e){
    $.ajax({
        url:rootURL+"selG",
        type:"get",
        async:true,
        success:function(Grade){
            $('#grade'+e).empty();
            var grade = Grade.extend.grade;
            $.each(grade, function(index, item) {
                $('<option value='+item.grade+'></option>').append(item.grade+'年级').appendTo('#grade'+e);
            });
        }
    });
}

//查询班级
function selClasss(grade,e){
    $.ajax({
        url:rootURL+"selC",
        type:"get",
        async:true,
        data:{
            grade:grade
        },
        success:function(Classs){
            $('#classs'+e).empty();
            var classs = Classs.extend.classs;
            $.each(classs, function(index, item) {
                $('<option value='+item.classs+' cla-id='+item.id+'></option>').append(item.classs+'班').appendTo('#classs'+e);
            });
        }
    });
}